Ext.define('Emp.ux.ImageUpload', {
	extend: 'Ext.panel.Panel',
	alias: 'widget.imageupload',

	requires: [
		'Ext.Img',
		'Ext.form.field.Text',
		'Ext.form.field.File',
		'Ext.button.Button'
	],
	
	src: Ext.BLANK_IMAGE_URL,
	
	initComponent: function() {
		var me = this;
		Ext.apply(this, {
			layout: 'absolute',
			items: [{
					xtype: 'textfield',
					name: this.name,
					hidden: true,
					listeners: {
						scope: me,
						'change': function(field, value) {
							if(Ext.String.trim(value) === '') {
								this.down('image').setSrc(this.src);
							} else {
								this.down('image').setSrc(PATH + value);
							}
						}
					}
				}, {
					xtype: 'image',
					src: this.src,
					x: 0,
					y: 0
				}, {
					xtype: 'filefield',
					name: 'file',
					buttonOnly: true,
					buttonText: '',
					buttonConfig: {
						iconCls: 'upload-icon'
					},
					x: this.width - 24,
					y: this.height - 24
//				}, {
//					xtype: 'button',
//					cls: Ext.baseCSSPrefix + 'form-file-btn',
//					iconCls: 'upload-icon',
//					x: this.width - 22,
//					y: this.height - 22,
//					handler: function(btn, e) {
//						//this.ownerCt.down('filefield').onTriggerWrapClick();
//						//this.ownerCt.down('filefield')['buttonEl-btnEl'].dom.click();
//						//this.ownerCt.down('filefield').triggerWrap.click();
//					}
			}]
		});
		
		this.callParent();
	}
});